<template>
  <div class="app-container">
    <el-collapse v-model="activeName" accordion>
      <el-collapse-item name="1">
        <template slot="title">
          <i class="el-icon-search" />搜索栏
        </template>
        <div class="head-container">
          <el-form v-if="show" class="searchform" :model="params" :inline="true" size="mini">
            <el-form-item label="部门+细分类(Dept+Fineline)">
              <el-input v-model="params.deptFineline" placeholder="输入对应列名搜索" clearable size="mini" style="width: 200px;" />
            </el-form-item>
            <el-form-item label="部门(Dept)">
              <el-input v-model="params.dept" placeholder="输入对应的列名搜索" clearable size="mini" style="width: 200px;" />
            </el-form-item>
            <el-form-item>
              <el-button size="mini" type="primary" style="float:right;margin-right:0px;" round icon="el-icon-refresh" @click="resetForm">重置</el-button>
              <el-button size="mini" type="primary" style="float:right;margin-right:0px;" round icon="el-icon-search" @click="toQuery">查询</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-collapse-item>
    </el-collapse>
    <div style="padding-top:5px">
      <el-button size="mini" type="danger" style="float:right;margin-bottom:5px;" icon="el-icon-remove" round @click="batchDelete">批量删除</el-button>
      <el-button size="mini" type="success" style="float:right;margin-bottom:5px;margin-right:0px;" icon="el-icon-circle-plus" round @click="addBpmsPlu">新增</el-button>
      <el-table :data="data" :row-key="getRowKeys" stripe size="small" border style="width: 100%;" @selection-change="handleSelectionChange">
        <el-table-column :reserve-selection="true" type="selection" align="center" width="55" />
        <el-table-column :show-overflow-tooltip="true" label="Dept+Fineline" prop="deptFineline" fixed="left" />
        <el-table-column :show-overflow-tooltip="true" label="Dept" prop="dept" fixed="left" />

        <el-table-column :show-overflow-tooltip="true" label="Fineline Nbr" prop="finelineNbr" />
        <el-table-column :show-overflow-tooltip="true" label="English" prop="english" />
        <el-table-column :show-overflow-tooltip="true" label="Fine Line" prop="fineLine" />
        <el-table-column :show-overflow-tooltip="true" label="Cat." prop="cat" />

        <el-table-column :show-overflow-tooltip="true" label="创建人" prop="createdBy" />
        <el-table-column :show-overflow-tooltip="true" label="最后更新人" prop="updatedBy" />
        <el-table-column :show-overflow-tooltip="true" label="创建时间" prop="createdTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createdTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="最后更新时间" prop="updatedTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updatedTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="185" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" type="warning" icon="el-icon-edit" round @click="updateBpmsPluOne(scope.row)">修改</el-button>
            <el-button size="mini" type="warning" icon="el-icon-remove" round @click="deleteBpmsPluOne(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <el-pagination
        :total="total"
        :current-page.sync="currentPage"
        style="margin-top: 8px;"
        layout="total, prev, pager, next, sizes"
        @size-change="sizeChange"
        @current-change="pageChange"
      />
    </div>
    <addBpmsPlu ref="addBpmsPlu" :parent="parent" />
  </div>
</template>

<script>
import { batchDeleteBpmsPlu, deleteBpmsPlu } from '@/api/plugs'
import initServiceData from '@/utils/initServiceData'
import addBpmsPlu from '@/views/system-manage/plugs/bpmsPlu/addBpmsPlu'
import { parseTime } from '@/utils/index'
import { Message } from 'element-ui'

export default {
  components: { addBpmsPlu },
  mixins: [initServiceData],
  data() {
    return {
      parent: this,
      activeName: '1',
      ruleApplyTypes: [{ name: '', value: null }],
      options: [],
      ids: [],
      show: true
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
    // this.loadApplyType()
    // this.loadSheetNames()
  },
  methods: {
    parseTime,
    beforeInit() {
      this.url = '/plugs/queryBpmsPluInfoList'
      this.params.pageNum = this.page
      this.params.pageSize = this.size
      return true
    },
    resetForm() {
      this.params = { rowSite: '', rowName: '', options: [] }
    },
    toQuery() {
      this.page = 0
      this.currentPage = 1
      this.init()
    },
    addBpmsPlu() {
      const _this = this.$refs.addBpmsPlu
      _this.dataInfo = {}
      _this.dialog = true
      _this.dialogStatus = 'addMap'
    },
    updateBpmsPluOne(row) {
      const _this = this.$refs.addBpmsPlu
      _this.dialog = true
      _this.dialogStatus = 'editMap'
      _this.dataInfo = Object.assign({}, row)
    },
    // 翻页选择row的key值
    getRowKeys(row) {
      return row.id
    },
    // 列表多选框触发
    handleSelectionChange(val) {
      this.ids = []
      val.forEach(item => {
        this.ids.push(item.id)
      })
    },
    // 批量删除
    batchDelete() {
      if (this.ids.length <= 0) {
        Message({
          message: '请选择删除项!',
          type: 'warning',
          duration: 2 * 1000
        })
        return
      }
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        batchDeleteBpmsPlu(this.ids).then(res => {
          Message({
            message: '操作成功',
            type: 'success',
            duration: 2 * 1000
          })
          this.toQuery()
        })
      })
    },
    deleteBpmsPluOne(row) {
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteBpmsPlu(row.id).then(res => {
          Message({
            message: '操作成功',
            type: 'success',
            duration: 2 * 1000
          })
          this.toQuery()
        })
      })
    }
    // formatIs(row, column) {
    //   return row.isAllowCommit === '1' ? '是' : '否'
    // }
  }
}
</script>
